package com.itita.ww2.handler.requesthandler.basemap;

import java.sql.SQLException;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.utils.handler.IRequestOper;

/**
 * 升级地图上的防御建筑
 * @author NorthLan
 *
 */
public class MapDefenceUpgrade implements IRequestOper {

	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		//		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		//		int uid = userProfile.getUid();
		//		String mapCode = params.getUtfString(R.DATA_KEY_CODE); // 地图单位编号 Map237489279218971823
		//
		//		// 
		//		ISFSObject backObj = new SFSObject();
		//		backObj.putInt(R.DATA_KEY_COUNTER, params.getInt(R.DATA_KEY_COUNTER));
		//		// 
		//
		//		// 用户是否在升级该单位
		//		if (UserService.getInstance().haveTime(uid, DevTimeType.UPGRADE, mapCode)) {
		//			MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, MsgCode.BASEMAP_UNIT_UPGRADING, false);
		//			return false;
		//		}
		//
		//		ISFSObject userMapData = UserService.getInstance().getUserMapdata(uid);
		//		//判断地图上是否有该单位
		//		if (!userMapData.containsKey(mapCode)) {
		//			MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, MsgCode.BASEMAP_MAP_UNIT_NOT_EXISTS, false);
		//			return false;
		//		}
		//
		//		ISFSObject mapunit = userMapData.getSFSObject(mapCode);
		//		// 获取建筑代号
		//		String bdCode = BaseMapUtil.getBuildCode(mapunit);
		//		// 获取建筑等级
		//		int bdLevel = BaseMapUtil.getBuildLevel(mapunit);
		//		// 判断该单位是否满足升级条件
		//		if (!UserService.getInstance().isBypassLimit(userProfile, bdCode, bdLevel)) {
		//			MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, MsgCode.BASEMAP_REQUIRE_NOT_REACHED, false);
		//			return false;
		//		}
		//
		//		// 消耗资源
		//		UserService.getInstance().consumeResOfBLL(userProfile, bdCode, bdLevel);
		//		// 推资源消息
		//		userProfile.getResManager().sync();
		//		// 添加升级时间以及计划
		//		String devKey = DevKeyUtil.combineKey(DevTimeType.UPGRADE.toString(), mapCode);
		//		long endTime = UserService.getInstance().addDevTimeOfBLL(uid, devKey, bdCode, bdLevel);
		//
		//		//发送成功信息
		//		backObj.putLong("endTime", endTime);
		//		backObj.putUtfString("key", devKey);
		//		//		backObj.putInt("count", 1);
		//		MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, null, true);
		return false;
	}

}
